"ui";
/*
作者:一只小阿磊（抠脚本人）
QQ:742374184
仅用于学习交流，请勿滥用
使用中任何问题，与本人无关，不同意请不要使用
*/
importClass('android.view.WindowManager');
var 全屏, 控件, 长按 = false
ui.layout(
    <vertical>
        <vertical  id="设置区">
            <horizontal>
                <text text="链接" paddingLeft="10dp" w="25dp" textSize="16dp" />
                <input id="链接" w="240dp" textSize="16dp" paddingBottom="20dp" h="60dp" inputType="textLongMessage" text="https://m.iqiyi.com/v_19rzexcum4.html" hint="粘贴视频地址" />
                <button id="解析" textSize="15dp" paddingTop="10dp" style="Widget.AppCompat.Button.Colored" textColor="White" gravity="center" w="60dp" h="60dp" margin="0 0 0 0" text="解析" />
                <button id="全屏" textSize="15dp" paddingTop="10dp" style="Widget.AppCompat.Button.Colored" textColor="White" gravity="center" w="60dp" h="60dp" margin="0 0 0 0" text="设置" />
            </horizontal>
        </vertical>
        <webview id="webview" hardwareAccelerated ="true" h="*"/>
    </vertical>
)
ui.statusBarColor("#90FCFCFC");
activity.getWindow().getDecorView().setSystemUiVisibility(android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
ui.webview.setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null);
var storage = storages.create("视频解析");
var 接口 = storage.get("接口");

if (接口 == null) {
    接口 = "https://jx.htv009.com/?url="
}

ui.解析.on("click", () => {
    if (长按 == false) {
        ui.webview.loadUrl(接口 + ui.链接.getText())
        打开全屏()
    }
    长按 = false
})

ui.解析.on("long_click", () => {
    长按 = true
    dialogs.singleChoice("请选择解析接口", ["大师解析", "我爱解析", "比思解析", "金桥解析", "紫云解析"], 0)
        .then(function(结果) {
            switch (结果) {
                case -1:
                    toast("未更改")
                    return;
                case 0:
                    接口 = "https://jx.htv009.com/?url=";
                    break;
                case 1:
                    接口 = "https://vip.52jiexi.top/?url="
                    break;
                case 3:
                    接口 = "https://beaacc.com/2/?url=";
                    break;
                case 3:
                    接口 = "https://5.nmgbq.com/2/?url=";
                    break;
                case 4:
                    接口 = "http://api.smq1.com/?url="
                    break;
            }
            storage.put("接口", 接口)
            ui.webview.loadUrl(接口 + ui.链接.getText())
            打开全屏()
        })

})

ui.全屏.on("click", () => {
    if (ui.全屏.text() == "设置") {
        app.startActivity("settings");
    } else {
        ui.全屏.setText("设置")
        打开全屏()
    }
})

function 打开全屏() {
    ui.设置区.setVisibility(8)
    activity.window.setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN, android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN); //设置全屏
    activity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    ui.run(() => {
        activity.setRequestedOrientation(0)
    })
    全屏 = true
    ui.全屏.setText("全屏")
    threads.start(无障碍设计)
}

function 取消全屏() {
    ui.设置区.setVisibility(0)
    activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    ui.run(() => {
        activity.setRequestedOrientation(1)
    })
    全屏 = false
}

ui.emitter.on("back_pressed", e => {
    if (全屏) {
        取消全屏()
        e.consumed = true;
    } else {
        e.consumed = false
    }
});

ui.emitter.on("resume", function() {
    let 剪切板 = getClip()
    if (剪切板.search("http") != -1) {
        ui.链接.setText(剪切板)
    }
});

events.on("exit", function() {
    toast("See you later~");
});

function 无障碍设计() {
    activity.getSystemService(activity.INPUT_METHOD_SERVICE).hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
}


var 拦截规则 = new JavaAdapter(android.webkit.WebViewClient, {
    shouldInterceptRequest: function(view, request) {
        let url = request.getUrl().toString();
        if (url.includes('cnzz') || url.includes('llrnlzl') || url.includes('img.hdsygw.cn') || url.includes('mg.btnvlvt.cn') || url.includes('kcdnam.cn') || url.includes('mosflower') || url.includes('yangniupiju') || url.includes('fengchedaomall') || url.includes('adinisp') || url.includes('xn--')) {
            return new android.webkit.WebResourceResponse(null, null, null);
        }
    }
})
ui.webview.setWebViewClient(拦截规则);